/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.cheetah.youbet.core.impl.sisal;

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.ResourceBundle;
import org.cheetah.youbet.download.PianetaScommesseDownload;
import org.cheetah.youbet.helper.IncontroHelper;
import org.cheetah.youbet.sql.Database;
import org.cheetah.youbet.core.Xls;
import org.cheetah.youbet.core.AbstractBetCore;

/**
 *
 * @author edoardo
 */
public class SisalBetCore extends AbstractBetCore {

    private static ResourceBundle bundle = ResourceBundle.getBundle("org.cheetah.youbet.etc.youbet");

    private String url = bundle.getString("url.http.palinsesto.sisal");

    @Override
    public InputStream downloadBooks() throws Exception {
        URL _url = new URL(url);
        URLConnection con = _url.openConnection();
        InputStream in = con.getInputStream();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        int ch = 0;
        byte[] buffer = new byte[1024];
        while ((ch = in.read(buffer)) > 0) {
            out.write(buffer, 0, ch);
        }
        in.close();
        out.flush();
        out.close();
        Xls xls = Xls.getInstance(out.toByteArray());

        return xls.write();
    }

    
    @Override
    public void downloadScores() throws Exception {
            List<Date> dates = new ArrayList<Date>();
            PianetaScommesseDownload dow = new PianetaScommesseDownload();
            dow.downloadScores();
    }

    @Override
    public void store(InputStream in) throws Exception {
        Xls.store(Database.getConnection(), in);
    }

    
}
